// pages/activity/sign_in/sign_in.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    days: 0,
    awards: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getSignDayInfo();
  },

  /**
   * 获取签到信息
   */
  getSignDayInfo: function() {
    app.Ajax({
      url: '/api/index.php?app=sign&act=sign',
      success: (res) => {
        this.setData({
          awards: res.awards,
          days: res.days
        })
      }
    })
  },

  /**
   * 签到
   */
  signIn: function() {
    app.Ajax({
      method: 'POST',
      url: '/api/index.php?app=sign&act=sign',
      success: (res) => {
        var message = '已连续签到' + res.days + '天，获得' + res.awards + '星星';
        this.setData({
          days: res.days,
          message: message
        })
      },
      fail: (err) => {
        this.setData({
          message: err
        })
      }
    })
  },
})